<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>注册帐号-第三方登录——66Play</title>
        <link rel="stylesheet" href="__PUBLIC__/Home/static/thirdpart/css/common.css">
        <script type="text/javascript" src="__PUBLIC__/Home/ui3/js/lib/jquery-1.8.2.min.js"></script>
    </head>
    <body>
        <div class="main">
            <div class="p_15">
                <div class="box pt_20">
                    <p class="text_name">
                        <img src="{$sso_avatar|default="__PUBLIC__/Home/static/temp_img/avatar.png"}" alt=""/>
                    </p>
                    <p class="text_name text_h1">
                        亲爱的用户
                    </p>
                    <p class="text_name text_h3" id="msg">
                        是否使用你的{$sso_channel}昵称登录66Play。
                    </p>
                </div>
                <div class="box">
                    <div class="input_box">
                        <div class="icon icon_name"></div>
                        <input class="input_sty" type="text" name="nickname" maxlength="16" value="{$sso_nickname}" oninput="check()" onblur="check()"/>
                    </div>
                    <input class="input_btn pa_r0t0 f16" type="button" onclick="submit()" value="确认" style=“width:60px;”>
                </div>
            </div>
        </div>
        <script>
            function check(){
                var nickname = $("input[name=nickname]").val();
                var myreg =/[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im;
                var s = myreg.test(nickname);
                if(s) {
                    $("#msg").text(nickname + ' ' + "昵称不合法");
                } else {
                    $.ajax({
                        url:"__ROOT__/api/visitor/checkNickname",
                        type:'post',
                        data:{nickname:nickname},
                        dataType:'json',
                        success:function(data){
                            $("#msg").text(nickname + ' ' + data.info);
                        }
                    });
                }
            }

            function submit(){
                var redirect_url = '{$redirect_url}';
                $.ajax({
                    url:"{:U('User/nickname')}",
                    data:{nickname:$("input[name=nickname]").val()},
                    type:'post',
                    dataType:'json',
                    success:function(data){
                        if(data.state < 0){
                            $("#msg").text(data.info);
                            return;
                        }else{
                            window.location.href= redirect_url;
                        }
                    }
                });
            }
            check();
        </script>
    </body>
</html>